﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FaultBackService.DAL
{
    class TenMeanData
    {
        /// <summary>
        /// 在数据库中写入多条记录
        /// </summary>
        /// <param name="tenMeanDataList"></param>
        internal void AddList(IList<Models.TenMeanData> tenMeanDataList)
        {
            using (Models.TurbineFaultContext context = new Models.TurbineFaultContext())
            {
                context.TenMeanData.AddRange(tenMeanDataList);
                context.SaveChanges();
            }
        }

        /// <summary>
        /// 获取某天的所有记录
        /// </summary>
        /// <param name="day"></param>
        /// <returns></returns>
        internal IList<Models.TenMeanData> GetList(DateTime day)
        {
            using (Models.TurbineFaultContext context = new Models.TurbineFaultContext())
            {
                return context.TenMeanData
                    .Where(d => d.TimeStamp.Date == day)
                    .OrderBy(d => d.TimeStamp)
                    .ToList();
            }
        }

        /// <summary>
        /// 获取故障数据库最新的十分钟数据
        /// </summary>
        /// <returns></returns>
        internal Models.TenMeanData GetLastOne()
        {
            using (Models.TurbineFaultContext context = new Models.TurbineFaultContext())
            {
                return context.TenMeanData
                    .OrderByDescending(d=>d.TenMeanId)
                    .FirstOrDefault();
            }
        }
    }
}
